<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
		<title></title>
		<link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.css" />
		<link rel="stylesheet" type="text/css" href="../pages/bill/css/mobiscroll.custom-2.5.0.min.css" />
		<link rel="stylesheet" type="text/css" href="../pages/bill/css/common.css" />
		<link rel="stylesheet" type="text/css" href="../pages/bill/css/bill.css" />
		<link rel="stylesheet" type="text/css" href="../pages/bill/css/scrollbar.css" />
		<script src="../pages/bill/js/jquery-1.11.3.min.js" type="text/javascript" charset="utf-8"></script>
		<script type="text/javascript">
			jQuery(function() {
				$('input').attr('data-role', 'none');
			})
		</script>
		<script src="http://code.jquery.com/mobile/1.3.1/jquery.mobile-1.3.1.min.js"></script>
		<script src="../pages/bill/js/mobiscroll.custom-2.5.0.min.js" type="text/javascript" charset="utf-8"></script>
		<script src="../pages/bill/js/iscroll.js" type="text/javascript" charset="utf-8"></script>
		<script src="../pages/bill/layer/layer.js" type="text/javascript" charset="utf-8"></script>
		<script src="../pages/bill/js/common.js" type="text/javascript" charset="utf-8"></script>

	</head>

	<body>
		<div class="container">
			<span class="changePass" data-role="none">修改密码</span>
			<header>
				<a href="javascript:;" class="out" data-role="none">退出</a>
				<span>商铺对账单</span>
			</header>
			<div class="content">
				<div class="topInfo">
					<div class="infoTime">
						<div class="timeFrom" id="date1">
							从&nbsp;<span id="fromYear" class="purple">2017</span>年<span id="fromMonth" class="purple">03</span>月<i></i>
						</div>
						<div class="timeTo" id="date2">
							从&nbsp;<span id="toYear" class="purple">2017</span>年<span id="toMonth" class="purple">04</span>月<i></i>
						</div>
						<div><input class="chk_1" type="checkbox" name="settleBill" id="settleBill" value="" checked="false" /><label for="settleBill"></label>仅显示欠缴</div>
					</div>
					<div class="line"></div>
					<div class="infoMoney">
						<p><span class="txt1">缴款率：</span><span class="txt2 green" id="jiaokuanlvnum">0.00%</span></p>
						<p><span class="txt1">应缴：</span><span class="txt2"><a id="yingjiaonum">0.00</a>元</span></p>
						<p><span class="txt1 green">已缴：</span><span class="txt2"><a class="green" id="yijiaonum">0.00</a>元</span></p>
						<p><span class="txt1 red">未缴：</span><span class="txt2"><a class="red" id="weijiaonum">0.00</a>元</span></p>
					</div>
				</div>
				<div class="search">
					<img src="../pages/bill/img/bill_search.png" id="searchImg" /><input type="text" name="search" id="search" placeholder="请输入商家代码或名称" class="searchTxt" />
					<img src="../pages/bill/img/bill_search_delete.png" class="searchDelete" id="searchDelete" />
				</div>
				<div class="navList">
					<ul class="nav">
						<li class=""><span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">全部项目</span><img src="../pages/bill/img/arrow_right_gray.png" /></li>
						<li class=""><span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">全部业态</span><img src="../pages/bill/img/arrow_right_gray.png" /></li>
						<li class=""><span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">全部楼宇</span><img src="../pages/bill/img/arrow_right_gray.png" /></li>
						<li class="last"><span style="white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">全部楼层</span><img src="../pages/bill/img/arrow_right_gray.png" /></li>
					</ul>
					<div class="navListContent">
						<ul class="on ul1">
							<li><span>全部项目</span><i class="on"></i></li>
						</ul>
						<ul class="ul2">
							<li><span>全部业态</span><i class="on"></i></li>
						</ul>
						<ul class="ul3">
							<li><span>全部楼宇</span><i class="on"></i></li>
						</ul>
						<ul class="ul4">
							<li><span>全部楼层</span><i class="on"></i></li>
						</ul>
					</div>
				</div>

				<div class="billContent" id="wrapper">
					<div id="scroller">
						<!--<div id="pullDown">
							<span class="pullDownIcon"></span><span class="pullDownLabel">下拉刷新...</span>
						</div>-->
						<ul class="display">
							<!--<li>
								<dl>
									<dt><img src="../pages/bill/img/bill_no_image_default.png"/></dt>
									<dd>
										<p>NW17111 &nbsp;<span>汪飞碟</span></p>
										<div class="yingjiao">
											<p>[应缴]</p>
											<p>4000.00元</p>
										</div>
										<div class="line"></div>
										
									</dd>
								</dl>
								<div class="weijiao">
									<p class="green">[已缴] 0.00元</p>
									<p class="red">[未缴] 4000.00元</p>
								</div>
								<div class="rowLine"></div>
							</li>-->

						</ul>
						<!--<div id="pullUp" style="display: none;">
							<span class="pullUpIcon"></span><span class="pullUpLabel">上拉加载更多...</span>
						</div>-->
					</div>
				</div>
			</div>
			<div id="timeshow"></div>
		</div>
		<script type="text/javascript">
			$(function() {
				//初始化
				var loginInfo = JSON.parse(localStorage.getItem("loginInfo")); //获取当前用户信息
				console.log(loginInfo)
				var storesArr = []; //存储stores所有uuid
				var pageCount = 0;
				var constIndex = 0;
				
				var building = null; //需要传入楼层的楼宇参数
				var storesT = []; //需要当做参数stores
				var storesT1 = [];
				var louyu = [];//点击的楼宇
				var louceng = [];//点击的楼层
				var yetai1 = {};
				var indexLouyu = null;//需要记录的当前楼宇
				var indexLouceng = null;//需要记录的当前楼层
				var indexProjects = null;//需要记录的当前项目
				var indexYetai = null;//需要记录的当前业态
				var liArr = []; //存储列表被选中索引
				var returnedLouyu = null;//记录返回的楼宇
				
				function init() {
					var mydate = new Date();
					var year = mydate.getFullYear();
					var month = mydate.getMonth() + 1;
					if(parseInt(month) < 10) {
						month = '0' + month;
					}
					$('#fromYear,#toYear').html(year);
					$('#fromMonth,#toMonth').html(month);
					if(loginInfo){
						for(var i = 0; i < loginInfo.stores.length; i++) {
							$('.navListContent ul.ul1').append('<li><span>' + loginInfo.stores[i].name + '</span><i></i></li>');
							storesArr[i] = loginInfo.stores[i].uuid;
						}
					}else{
						window.location.href = 'tologin.thor';
					}
					
					
					//将标签筛选框高度适应屏幕
					$('.navListContent').height($('body').height()-278);
					
					if($('#settleBill').prop('checked')){//如果初始化页面的checkboc选中，取消，默认不勾选。
						$('#settleBill').prop('checked', false);
					}
					//如果当前页有记录数据，根据当前页数据初始化页面
					var rememberInfo = JSON.parse(sessionStorage.getItem("rememberInfo"));
//					console.log(rememberInfo);
					if(rememberInfo){
						var fromYear = rememberInfo.beginSettle.substring(0, 4);//开始年份
						var fromMonth = rememberInfo.beginSettle.substring(4, 6);//开始月份
						var toYear = rememberInfo.endSettle.substring(0, 4);//结束年份
						var toMonth = rememberInfo.endSettle.substring(4, 6);//结束月份
	
						$('#fromYear').html(fromYear);
						$('#fromMonth').html(fromMonth);
						$('#toYear').html(toYear);
						$('#toMonth').html(toMonth);
						
						var checked = rememberInfo.checked;//是否选中
						if(checked){
							$('#settleBill').prop('checked', true);
						}else{
							$('#settleBill').prop('checked', false);
						}
						
						$('#scroller ul.display').empty();//清空页面
						
						var indexProjectsn = rememberInfo.indexProjects;//项目索引
						var indexYetain = rememberInfo.indexYetai;//业态索引
						var indexLouyun = rememberInfo.indexLouyu;//楼宇索引
						var indexLoucengn = rememberInfo.indexLouceng;//楼层索引
						var keywords = rememberInfo.keywords;//关键字
						liArr = rememberInfo.liArr;//记录的下拉索引
						if(keywords == ''){
							keywords = null;
						}
						var stroesIds = "";
						var yetaiUuid = null;
						var louyuUuid = null;
						var loucengUuid = null;
						if(indexProjectsn != null){
							$('.nav li').eq(0).find('span').text(indexProjectsn.name);
							var arr = [];
							if(jQuery.isArray(indexProjectsn.id)){
								arr = indexProjectsn.id;
							}else{
								arr.push(indexProjectsn.id);
							}
							stroesIds = arr;
							storesT = arr;
							$('.navListContent ul.ul1 li').each(function(){
								if($(this).find('span').html() == indexProjectsn.name){
									$(this).children('i').addClass('on');
									$(this).siblings().children('i').removeClass("on");
								}
							})
						}else{
							stroesIds = storesArr;
						}
						if(indexYetain == null){
							$('.nav li').eq(1).find('span').text("全部业态");
						}else{
							$('.nav li').eq(1).find('span').text(indexYetain.name);
							yetaiUuid = indexYetain;
							yetai = indexYetain;
						}
						if(indexLouyun == null){
							$('.nav li').eq(2).find('span').text("全部楼宇");
						}else{
							$('.nav li').eq(2).find('span').text(indexLouyun.name);
							louyuUuid = indexLouyun;
							returnedLouyu = indexLouyun;
							building = indexLouyun;
						}
						if(indexLoucengn == null){
							$('.nav li').eq(3).find('span').text("全部楼层");
						}else{
							$('.nav li').eq(3).find('span').text(indexLoucengn.name);
							loucengUuid = indexLoucengn;
						}
						searchBill(stroesIds, keywords, 0, yetaiUuid, louyuUuid, loucengUuid);
						
						setTimeout(function(){
							sessionStorage.removeItem("rememberInfo");
						},100)
					}else{
						searchBill(storesArr); //进入页面直接加载
					}
				}
				init();

				//导航列表点击事件
				
				var yetaiindex = 0;
				var louyuIndex = 0;
				var loucengIndex = 0;
				$('.nav li').click(function() {
					nextpage = 2;
					var reg = new RegExp('on');
					if(!reg.test($(this).attr('class'))) {
						$(this).addClass('on').siblings().removeClass('on');
						$(this).children('img').attr('src', '../pages/bill/img/arrow_dwon_gray.png');
						$(this).siblings().children('img').attr('src', '../pages/bill/img/arrow_right_gray.png');
						$('.navListContent').show();
						$('.display').hide();
					} else {
						$(this).children('img').attr('src', '../pages/bill/img/arrow_right_gray.png');
						$(this).siblings().children('img').attr('src', '../pages/bill/img/arrow_right_gray.png');
						$(this).removeClass('on');
						$('.navListContent').hide();
						$('.display').show();
					}
					var index = $(this).index();
					$('.navListContent ul').hide();
					$('.navListContent ul').eq(index).show();
					for(var i = 0; i < loginInfo.stores.length; i++) {
						storesArr[i] = loginInfo.stores[i].uuid;
					}
//					console.log(storesArr)
					if(storesT.length == 0){
						storesT = storesArr;
					}
					if(index == 1) { //点击全部业态
						yetaifun();
						
					} else if(index == 2) { //点击全部楼宇
						louyufun(storesT);
						
					} else if(index == 3) { //点击全部楼层
						loucengfun(building, storesT);
						
					}
				})
				//下拉选项添加点击事件
				$('.navListContent ul').on('click', 'li', function() {
					var index = $(this).index();
					constIndex = index;
					$(this).children('i').addClass('on');
					$(this).siblings().children('i').removeClass('on');

					var ul1 = new RegExp('ul1'); //全部项目
					var ul2 = new RegExp('ul2'); //全部业态
					var ul3 = new RegExp('ul3'); //全部楼宇
					var ul4 = new RegExp('ul4'); //全部楼宇

					for(var i = 0; i < loginInfo.stores.length; i++) {
						storesArr[i] = loginInfo.stores[i].uuid;
					}

					if(ul1.test($(this).parent().attr('class')) && index != 0) { //点击全部项目非第一行
						storesT1[0] = storesArr[index - 1]; //将单项数据UUID传递
						storesT = storesT1;
						indexProjects = {
							name:$(this).find('span').html(),
							id:storesArr[index - 1]
						}
					} else if(ul1.test($(this).parent().attr('class')) && index == 0){
						storesT = storesArr; //传递所有UUID
						indexProjects = {
							name:$(this).find('span').html(),
							id:storesT
						}
					}
					
					
					//判断是否点击列表,将列表中的文字替换标题
					var keywords = null; //搜索关键字
					if(ul3.test($(this).parent().attr('class'))) {
						louyuIndex = index;
						building = louyuArr[index - 1];
						keywords = $(this).children('span').text();
						$('.nav li').eq(2).find('span').text(keywords);
						
						if(keywords == '全部楼宇') {
							keywords = null;
							louyu[index-1] = null;
							indexLouyu = null;
						}else{
							louyu = JSON.parse(sessionStorage.getItem('allLouyu'));
							indexLouyu = louyu[index-1];
							
						}
						liArr[1] = index;
						layer.load(2);
						setTimeout(function() {
							layer.closeAll('loading');
							$('#scroller ul.display').empty();
							searchBill(storesT, null,0,yetai1,louyu[index-1]);
							$('.nav li').eq(2).children('img').attr('src', '../pages/bill/img/arrow_right_gray.png');
							$('.nav li').eq(2).removeClass('on');
							$('.navListContent').hide();
							$('.display').show();
						}, 500);
					} else if(ul1.test($(this).parent().attr('class'))) {
						keywords = $(this).children('span').text();
						$('.nav li').eq(0).find('span').text(keywords);
						for(var i = 0; i < loginInfo.stores.length; i++) {
							storesArr[i] = loginInfo.stores[i].uuid;
						}
						if(keywords == '全部项目') {
							keywords = null;
							storesT = storesArr;
						}
//						console.log(storesT)
						layer.load(2);
						setTimeout(function() {
							layer.closeAll('loading');
							$('#scroller ul.display').empty();
							searchBill(storesT);
							$('.nav li').eq(0).children('img').attr('src', '../pages/bill/img/arrow_right_gray.png');
							$('.nav li').eq(0).removeClass('on');
							$('.navListContent').hide();
							$('.display').show();
						}, 500);
					} else if(ul2.test($(this).parent().attr('class'))) {
						yetaiindex = index;
						keywords = $(this).children('span').text();
						$('.nav li').eq(1).find('span').text(keywords);
						var yetai = '';//点击的业态
						
						if(keywords == '全部业态') {
							keywords = null;
							yetai1 = null;
							indexYetai = null;
						}else{
							yetai = JSON.parse(sessionStorage.getItem('allYetai'));
							yetai1 = {
								uuid: yetai[index-1].uuid,
						        code: yetai[index-1].code,
						        name: yetai[index-1].name,
							}
							indexYetai = yetai1;
						}
						liArr[0] = index;
						layer.load(2);
						setTimeout(function() {
							layer.closeAll('loading');
							$('#scroller ul.display').empty();
							searchBill(storesT, null,0,yetai1);
							$('.nav li').eq(1).children('img').attr('src', '../pages/bill/img/arrow_right_gray.png');
							$('.nav li').eq(1).removeClass('on');
							$('.navListContent').hide();
							$('.display').show();
						}, 500);
					} else if(ul4.test($(this).parent().attr('class'))) {
						loucengIndex = index;
						keywords = $(this).children('span').text();
						$('.nav li').eq(3).find('span').text(keywords);
						
						if(keywords == '全部楼层') {
							keywords = null;
							louceng[index-1] = null;
							indexLouceng = null;
						}else{
							louceng = JSON.parse(sessionStorage.getItem('allLouceng'));
							indexLouceng = louceng[index-1];
							if(returnedLouyu != null){//?????????????
								louyu[louyuIndex-1] = returnedLouyu;
							}
						}
						liArr[2] = index;
						layer.load(2);
						setTimeout(function() {
							layer.closeAll('loading');
							$('#scroller ul.display').empty();
							searchBill(storesT, null, 0, yetai1,louyu[louyuIndex-1], louceng[index-1]);
							$('.nav li').eq(3).children('img').attr('src', '../pages/bill/img/arrow_right_gray.png');
							$('.nav li').eq(3).removeClass('on');
							$('.navListContent').hide();
							$('.display').show();
						}, 500);
					}
				})

				//---------------------查询业态
				function yetaifun() {
					var yetaiArr = []; //存储业态所有数据
					$.ajax({
						url: "getBizType.thor?onlyUpper=true",
						cache: false,
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						success: function(data) {
							console.log(data);
							sessionStorage.setItem('allYetai',JSON.stringify(data));
							
							var len = data.length;
							$('.navListContent ul.ul2 li').not($('.navListContent ul.ul2 li:first')).empty().remove();
							for(var i = 0; i < len; i++) {
								$('.navListContent ul.ul2').append('<li><span>' + data[i].name + '</span><i></i></li>');
								yetaiArr[i] = data[i];

							}
							if(liArr[0]) {
								setTimeout(function(){
									$('.navListContent ul.ul2 li').eq(liArr[0]).children('i').addClass('on');
									$('.navListContent ul.ul2 li').eq(liArr[0]).siblings().children('i').removeClass("on");
								},10)
							}
						},
						error: function(data) {
							var data = JSON.stringify(data)
							layer.msg("查询失败")
						}
					});
				}
				//---------------------查询业态
				//---------------------------查询楼宇
				var louyuArr = []; //存储楼宇所有数据
				function louyufun(storesArr) {
					var buildParam = {};
					buildParam.stores = storesArr;

					$.ajax({
						url: "getBuildings.thor",
						cache: false,
						data: {
							buildParam: JSON.stringify(buildParam)
						},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						success: function(data) {
							console.log(data);
							sessionStorage.setItem('allLouyu',JSON.stringify(data));
							
							$('.navListContent ul.ul3 li').not($('.navListContent ul.ul3 li:first')).empty().remove();
							var len = data.length;
							for(var i = 0; i < len; i++) {
								$('.navListContent ul.ul3').append('<li><span>' + data[i].name + '</span><i></i></li>');
								louyuArr[i] = data[i];
							}
							if(liArr[1]) {
								setTimeout(function(){
									$('.navListContent ul.ul3 li').eq(liArr[1]).children('i').addClass('on');
									$('.navListContent ul.ul3 li').eq(liArr[1]).siblings().children('i').removeClass("on");
								},10)
							}
						},
						error: function(data) {
							var data = JSON.stringify(data)
							layer.msg("查询失败")
						}
					});
				}
				//---------------------------查询楼宇
				//-------------------------查询楼层
				function loucengfun(building, storesArr) {
					var loucengArr = []; //存储楼层所有数据
					var floorParam = {};
					floorParam.stores = storesArr;
					floorParam.building = building;

					$.ajax({
						url: "getFloors.thor",
						cache: false,
						data: {
							floorParam: JSON.stringify(floorParam)
						},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						success: function(data) {
							console.log(data);
							sessionStorage.setItem('allLouceng',JSON.stringify(data));
							
							$('.navListContent ul.ul4 li').not($('.navListContent ul.ul4 li:first')).empty().remove();
							var len = data.length;
							for(var i = 0; i < len; i++) {
								$('.navListContent ul.ul4').append('<li><span>' + data[i].name + '</span><i></i></li>');
								loucengArr[i] = data[i];
							}
							if(liArr[2]) {
								setTimeout(function(){
									$('.navListContent ul.ul4 li').eq(liArr[2]).children('i').addClass('on');
									$('.navListContent ul.ul4 li').eq(liArr[2]).siblings().children('i').removeClass("on");
								},10)
							}
						},
						error: function(data) {
							var data = JSON.stringify(data)
							layer.msg("查询失败")
						}
					});
				}
				//-------------------------查询楼层
				//---------------------------查询加载账单数据
				var contract = [];

				function searchBill(storesArr, keyWords, page, bizType, building, floor) {
					var beginSettle = $('#fromYear').html() + $('#fromMonth').html(); //开始时间参数
					var endSettle = $('#toYear').html() + $('#toMonth').html(); //结束时间参数
					var keyWords = $('#search').val() || keyWords || null; //搜索关键字
					var stores = storesArr; //stores
					var userGroups = loginInfo.userGroups; //用户组
					var page = page || 0;
					if(bizType == undefined){
						bizType = null;
					}
					if(building == undefined){
						building = null;
					}
					if(floor == undefined){
						floor = null;
					}
					var sessionContracts = JSON.parse(sessionStorage.getItem('sessionContracts'));//获取本地存储的用户协议
					var nowContracts = '';
					if(sessionContracts){
						nowContracts = sessionContracts;
					}else{
						nowContracts = [];
					}
					var queryParam = { //传参
						pageSize: 999,
						page: page,
						beginSettle: beginSettle,
						endSettle: endSettle,
						keyWords: keyWords,
						stores: stores,
						contracts: nowContracts,
						userGroups: userGroups,
						bizType: bizType,
						building: building,
						floor: floor,
					};
					
					$.ajax({
						url: "queryByStore.thor",
						cache: false,
						data: {
							queryParam: JSON.stringify(queryParam)
						},
						dataType: 'json', //服务器返回json格式数据
						type: 'post', //HTTP请求类型
						timeout: 10000, //超时时间设置为10秒；
						success: function(data) {
//							console.log(data);
							var pageSize = data.result.recordCount;
							queryParam = { //传参
								pageSize: pageSize,
								page: page,
								beginSettle: beginSettle,
								endSettle: endSettle,
								keyWords: keyWords,
								stores: stores,
								contracts: nowContracts,
								userGroups: userGroups,
								bizType: bizType,
								building: building,
								floor: floor,
							};
//							console.log(queryParam);
							$.ajax({
								url: "queryByStore.thor",
								cache: false,
								data: {
									queryParam: JSON.stringify(queryParam)
								},
								dataType: 'json', //服务器返回json格式数据
								type: 'post', //HTTP请求类型
								timeout: 20000, //超时时间设置为10秒；
								success: function(data) {
									console.log(data);
									layer.closeAll('loading');
									localStorage.setItem('allTenant',JSON.stringify(data.result.records));//本地存储返回的所有数据
									if(data.result.pageCount == 0) {
										layer.msg('暂时没有数据');
									}
									pageCount = data.result.pageCount;
									$('#jiaokuanlvnum').html(data.receiptRate.toPercent());
									$('#yingjiaonum').html(data.payTotal);
									$('#yijiaonum').html(data.payedTotal);
									$('#weijiaonum').html(data.unpayedTotal);
									var recordCount = data.result.recordCount; //查询总记录数
									var records = data.result.records;
									
									contract.splice(0, contract.length); //清空contract数组
									for(var i = 0; i < records.length; i++) {
										$('#scroller ul.display').append('<li>' +
											'<dl>' +
											'<dt><img src="../pages/bill/img/bill_no_image_default.png"/></dt>' +
											'<dd>' +
											'<p>' + records[i].tenant.code + ' &nbsp;<span class="billName">' + records[i].tenant.name + '</span></p>' +
											'<div class="yingjiao">' +
											'<p>[应缴]</p>' +
											'<p>' + records[i].payTotal + '元</p>' +
											'</div>' +
											'<div class="line"></div>' +
											'</dd>' +
											'</dl>' +
											'<div class="weijiao">' +
											'<p class="green">[已缴] <span class="yjnum green">' + records[i].payedTotal + '</span>元</p>' +
											'<p class="red">[未缴] <span class="wjnum red">' + records[i].unpayedTotal + '</span>元</p>' +
											'</div>' +
											'<div class="rowLine"></div>' +
											'</li>');
										contract.push(records[i].contract.uuid); //将获取的数据contract.uuid加入数组
									}
									
									var count = 0;
									if($('#settleBill').prop('checked')) {
										$('#scroller ul.display li').each(function() {
											var self = this;
											if(parseInt($(self).find('span.wjnum').text()) == 0) {
												count += Number($(self).find('span.yjnum').text())*100;
												$(self).hide();
											}
										})
//										var jiaofeilv = 0.00;
//										$('#yijiaonum').html((Number($('#yijiaonum').text())*100 - count)/100);
//										if(Number($('#yingjiaonum').text()>0)){
//											jiaofeilv = Number($('#yijiaonum').text())/Number($('#yingjiaonum').text());
//										}
//										$('#jiaokuanlvnum').html(jiaofeilv.toPercent());
									} else {
										$('#scroller ul.display li').each(function() {
											var self = this;
											if(parseInt($(self).find('span.wjnum').text()) == 0) {
												count += Number($(self).find('span.yjnum').text())*100;
												$(self).show();
											}
										})
//										var jiaofeilv = 0.00;
//										$('#yijiaonum').html((Number($('#yijiaonum').text())*100 + count)/100);
//										if(Number($('#yingjiaonum').text()>0)){
//											jiaofeilv = Number($('#yijiaonum').text())/Number($('#yingjiaonum').text());
//										}
//										$('#jiaokuanlvnum').html(jiaofeilv.toPercent());
									}
		
								},
								error: function(data) {
									var data = JSON.stringify(data)
									layer.closeAll('loading');
									layer.msg("查询失败")
		
								}
							});

						},
						error: function(data) {
							var data = JSON.stringify(data)
							layer.closeAll('loading');
							layer.msg("查询失败")

						}
					});
					
				}

				//---------------------------查询加载账单数据
				//--------------------------初始化日期控件
				var opt = {
					preset: 'date', //日期
					theme: 'android-ics light', //皮肤样式
					display: 'modal', //显示方式 
					mode: 'scroller', //日期选择模式
					dateFormat: 'yy-mm', // 日期格式
					setText: '确定', //确认按钮名称
					cancelText: '取消', //取消按钮名籍我
					dateOrder: 'yymm', //面板中日期排列格式
					dayText: '日',
					monthText: '月', //面板中年月文字
					endYear: 2020, //结束年份
					onSelect: function(valueText, inst) {
						var dateArr = valueText.split("-");
						var year = dateArr[0];
						var month = dateArr[1];
						nextpage = 2;
						if(timeIndex == 0) {
							$('#fromYear').html(year);
							$('#fromMonth').html(month);
							$('#scroller ul.display').empty();
							searchBill(storesArr);
						} else {
							$('#toYear').html(year);
							$('#toMonth').html(month);
							$('#scroller ul.display').empty();
							searchBill(storesArr);
						}
					}
				};
				var timeIndex = 0;
				$("#date1").click(function() {
					timeIndex = 0;
					$('#timeshow').mobiscroll('show');
				});
				$("#date2").click(function() {
					timeIndex = 1;
					$('#timeshow').mobiscroll('show');
				});
				$('#timeshow').mobiscroll().date();
				$('#timeshow').mobiscroll(opt);
				//--------------------------初始化日期控件
				//--------------------------搜索框点击事件
				$('#searchImg').click(function() {
					var allTenant = JSON.parse(localStorage.getItem('allTenant'));
					var keywords = new RegExp($('#search').val());
					$('#scroller ul.display').empty();
					var temp = 0;
					for(var i=0; i<allTenant.length; i++){
						var tenant = allTenant[i].tenant;
						if(keywords.test(tenant.name)){
							temp++;
							$('#scroller ul.display').append('<li>' +
									'<dl>' +
									'<dt><img src="../pages/bill/img/bill_no_image_default.png"/></dt>' +
									'<dd>' +
									'<p>' + allTenant[i].tenant.code + ' &nbsp;<span class="billName">' + allTenant[i].tenant.name + '</span></p>' +
									'<div class="yingjiao">' +
									'<p>[应缴]</p>' +
									'<p>' + allTenant[i].payTotal + '元</p>' +
									'</div>' +
									'<div class="line"></div>' +
									'</dd>' +
									'</dl>' +
									'<div class="weijiao">' +
									'<p class="green">[已缴] <span class="yjnum green">' + allTenant[i].payedTotal + '</span>元</p>' +
									'<p class="red">[未缴] <span class="wjnum red">' + allTenant[i].unpayedTotal + '</span>元</p>' +
									'</div>' +
									'<div class="rowLine"></div>' +
									'</li>');
						}
					}
					if(temp == 0){
						layer.msg("未查询到数据")
					}
//					searchBill(storesArr);
				})
				$('#searchDelete').click(function() {
					$('#search').val('');
				})
				//--------------------------搜索框点击事件
				//--------------------------点击进入详情页
				$('#scroller ul.display').on('click', 'li', function() {
					var index = $(this).index();
					var beginSettle = $('#fromYear').html() + $('#fromMonth').html(); //开始时间参数
					var endSettle = $('#toYear').html() + $('#toMonth').html(); //结束时间参数
					var topName = $(this).find('span.billName').html();
					sessionStorage.setItem('topName', topName);
					var checked = $('#settleBill').prop('checked');//checkedbox是否选中
					var keywords = $('#search').val();//搜索关键字
					//记录当前页的信息，从详情页返回当前页时，展示离开的时候的样子
					var rememberInfo = {
						beginSettle:beginSettle,
						endSettle:endSettle,
						checked:checked,
						indexProjects:indexProjects,
						indexYetai:indexYetai,
						indexLouyu:indexLouyu,
						indexLouceng:indexLouceng,
						keywords:keywords,
						liArr:liArr,
					}
					sessionStorage.setItem('rememberInfo',JSON.stringify(rememberInfo));
					window.location.href = 'tobillDetail.thor?contract=' + encodeURI(contract[index]) + '&beginSettle=' + encodeURI(beginSettle) + '&endSettle=' + encodeURI(endSettle);
				})
				//--------------------------点击进入详情页
				//--------------是否显示结清账户
				$('#settleBill').change(function() {
					var count = 0;
					if($('#settleBill').prop('checked')) {
						$('#scroller ul.display li').each(function() {
							var self = this;
							if(parseInt($(self).find('span.wjnum').text()) <= 0) {
								count += Number($(self).find('span.yjnum').text())*100;
								$(self).hide();
							}
						})
//						var jiaofeilv = 0.00;
//						$('#yijiaonum').html((Number($('#yijiaonum').text())*100 - count)/100);
//						if(Number($('#yingjiaonum').text()>0)){
//							jiaofeilv = Number($('#yijiaonum').text())/Number($('#yingjiaonum').text());
//						}
//						$('#jiaokuanlvnum').html(jiaofeilv.toPercent());
					} else {
						$('#scroller ul.display li').each(function() {
							var self = this;
							if(parseInt($(self).find('span.wjnum').text()) <= 0) {
								count += Number($(self).find('span.yjnum').text())*100;
								$(self).show();
							}
						})
//						var jiaofeilv = 0.00;
//						$('#yijiaonum').html((Number($('#yijiaonum').text())*100 + count)/100);
//						if(Number($('#yingjiaonum').text()>0)){
//							jiaofeilv = Number($('#yijiaonum').text())/Number($('#yingjiaonum').text());
//						}
//						$('#jiaokuanlvnum').html(jiaofeilv.toPercent());
					}
				})
				//--------------用户退出，清空本地数据
				$('.out').click(function() {
					localStorage.clear();
					sessionStorage.clear();
					window.location.href = 'tologin.thor';
				});
				
				//场景滚动加载更多
				var nextpage = 2;
				
				//点击修改密码事件
				$('.changePass').click(function(){
					window.location.href = "tochangePass.thor?id=" + loginInfo.code;
				})
			})
		</script>
		<script type="text/javascript">
			//滑动刷新加载
			var myScroll,
				pullDownEl, pullDownOffset,
				pullUpEl, pullUpOffset,
				generatedCount = 0;

			/**
			 * 下拉刷新 （自定义实现此方法）
			 * myScroll.refresh();		// 数据加载完成后，调用界面更新方法
			 */
			function pullDownAction() {
				setTimeout(function() {
					//添加执行方法
					console.log('下拉');
//					$('#scroller ul.display').empty();
					//					searchBill(storesArr);
					myScroll.refresh(); //数据加载完成后，调用界面更新方法   
				}, 1000);
			}

			/**
			 * 滚动翻页 （自定义实现此方法）
			 * myScroll.refresh();		// 数据加载完成后，调用界面更新方法
			 */
			function pullUpAction() {
				setTimeout(function() {
					//添加执行方法
					console.log('上拉')
//					$('#scroller ul.display').empty();
					//					searchBill(storesArr);
					myScroll.refresh(); // 数据加载完成后，调用界面更新方法 
				}, 1000);
			}
			/**
			 * 初始化iScroll控件
			 */
			function loaded() {
				pullDownEl = document.getElementById('pullDown');
				pullDownOffset = pullDownEl.offsetHeight;
				pullUpEl = document.getElementById('pullUp');
				pullUpOffset = pullUpEl.offsetHeight;

				myScroll = new iScroll('wrapper', {
					scrollbarClass: 'myScrollbar',
					/* 重要样式 */
					useTransition: false,
					/* 此属性不知用意，本人从true改为false */
					topOffset: pullDownOffset,
					onRefresh: function() {
						if(pullDownEl.className.match('loading')) {
							pullDownEl.className = '';
							pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
						} else if(pullUpEl.className.match('loading')) {
							pullUpEl.className = '';
							pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
						}
					},
					onScrollMove: function() {
						if(this.y > 5 && !pullDownEl.className.match('flip')) {
							pullDownEl.className = 'flip';
							pullDownEl.querySelector('.pullDownLabel').innerHTML = '松手开始更新...';
							this.minScrollY = 0;
						} else if(this.y < 5 && pullDownEl.className.match('flip')) {
							pullDownEl.className = '';
							pullDownEl.querySelector('.pullDownLabel').innerHTML = '下拉刷新...';
							this.minScrollY = -pullDownOffset;
						} else if(this.y < (this.maxScrollY - 5) && !pullUpEl.className.match('flip')) {
							pullUpEl.className = 'flip';
							pullUpEl.querySelector('.pullUpLabel').innerHTML = '松手开始更新...';
							this.maxScrollY = this.maxScrollY;
						} else if(this.y > (this.maxScrollY + 5) && pullUpEl.className.match('flip')) {
							pullUpEl.className = '';
							pullUpEl.querySelector('.pullUpLabel').innerHTML = '上拉加载更多...';
							this.maxScrollY = pullUpOffset;
						}
					},
					onScrollEnd: function() {
						if(pullDownEl.className.match('flip')) {
							pullDownEl.className = 'loading';
							pullDownEl.querySelector('.pullDownLabel').innerHTML = '加载中...';
							pullDownAction(); // Execute custom function (ajax call?)
						} else if(pullUpEl.className.match('flip')) {
							pullUpEl.className = 'loading';
							pullUpEl.querySelector('.pullUpLabel').innerHTML = '加载中...';
							pullUpAction(); // Execute custom function (ajax call?)
						}
					}
				});

				setTimeout(function() {
					document.getElementById('wrapper').style.left = '0';
				}, 800);
			}
//			window.addEventListener('touchmove', function(e) {
//				e.preventDefault();
//			}, false);
//			window.addEventListener('load', loaded, false);
		</script>
	</body>

</html>